package com.wxsh;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.wxsh.entity.User;
import com.wxsh.service.UserService;

public class App {

	private static ApplicationContext context;

	public static void main(String[] args) {
		
		context = new ClassPathXmlApplicationContext("classpath:spring/applicationContext.xml");
//		context = new ClassPathXmlApplicationContext("classpath:spring/spring-service.xml", "classpath:spring/spring-dao.xml");
//		context = new ClassPathXmlApplicationContext("/spring/spring-service.xml", "/spring/spring-dao.xml");
//		context = new ClassPathXmlApplicationContext("spring/spring-service.xml", "spring/spring-dao.xml");
//		UserService userService = context.getBean(UserService.class);
//		UserService userService = context.getBean(UserServiceImpl.class);
//		UserService userService = (UserService) context.getBean("userServiceImpl");
//		UserService userService = context.getBean("userServiceImpl", UserService.class);
		//推荐这种写法
		UserService userService = (UserService) context.getBean("userServiceImpl");
		User user = userService.findById(1);
		System.out.println(user.getUserName());
		User u1 = new User();
		u1.setUserName("wxsh1");
		userService.addUser(u1);
		System.out.println(u1.getId());
	}

}
